package org.wu.framework.log.spring.starter.tips;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.util.ObjectUtils;

import java.io.File;

/**
 * description 打印日志提示信息
 *
 * @author 吴佳伟
 * @date 2023/06/27 10:35
 */
@Slf4j
public class LogPathTips implements InitializingBean {
    private final ConfigurableEnvironment configurableEnvironment;

    public LogPathTips(ConfigurableEnvironment configurableEnvironment) {
        this.configurableEnvironment = configurableEnvironment;
    }


    /**
     * Invoked by the containing {@code BeanFactory} after it has set all bean properties
     * and satisfied {@link BeanFactoryAware}, {@code ApplicationContextAware} etc.
     * <p>This method allows the bean instance to perform validation of its overall
     * configuration and final initialization when all bean properties have been set.
     *
     * @throws Exception in the event of misconfiguration (such as failure to set an
     *                   essential property) or if initialization fails for any other reason
     */
    @Override
    public void afterPropertiesSet() throws Exception {
        log.info("配置日志模块启动详细日志如下:");
        String applicationName = configurableEnvironment.getProperty("spring.application.name");
        String rootDir = System.getProperty("user.dir");
        rootDir = ObjectUtils.isEmpty(File.separator) ? File.separator : rootDir + File.separator;
        if (!ObjectUtils.isEmpty(applicationName)) {
            System.out.println("==================================================================================\n");
            System.out.println(
                    "info日志: " + rootDir + "logs" + File.separator + applicationName + File.separator + applicationName + "_logback_info.log\n" +
                            "error日志: " + rootDir + "logs" + File.separator + applicationName + File.separator + applicationName + "_logback_error.log\n" +
                            "debug日志: " + rootDir + "logs" + File.separator + applicationName + File.separator + applicationName + "_logback_debug.log\n" +
                            "mysql执行日志: " + rootDir + "logs" + File.separator + applicationName + File.separator + applicationName + "_logback_mysql.log\n" +
                            "告警信息日志: " + rootDir + "logs" + File.separator + applicationName + File.separator + applicationName + "_logback_warn.log\n"

            );
            System.out.println("==================================================================================");
        }

    }
}
